#pragma once

#include "iskia_control.h"

#include <memory>
#include <list>

class SkiaControlBase : virtual public ISkiaControl {
public:
    ~SkiaControlBase() override = default;

    void AppendChild(const std::shared_ptr<ISkiaControl> &child)
    {
        children_.push_back(child);
    }

    bool IsContain(int32_t x, int32_t y) override
    {
        for (auto &child : children_) {
            if (child->IsContain(x, y)) {
                return true;
            }
        }

        return false;
    }

    void OnMouseMotion(int32_t x, int32_t y) override
    {
        for (auto &child : children_) {
            child->OnMouseMotion(x, y);
        }
    }

    void OnMouseDown(int32_t x, int32_t y) override
    {
        for (auto &child : children_) {
            child->OnMouseDown(x, y);
        }
    }

    void OnMouseUp() override
    {
        for (auto &child : children_) {
            child->OnMouseUp();
        }
    }

    void OnClick(int32_t x, int32_t y) override
    {
        for (auto &child : children_) {
            if (child->IsContain(x, y)) {
                child->OnClick(x, y);
            }
        }
    }

    void OnDraw(SkCanvas &canvas) override
    {
        for (auto &child : children_) {
            child->OnDraw(canvas);
        }
    }

private:
    std::list<std::shared_ptr<ISkiaControl>> children_;
};
